package com.kk.permission.huawei.actionutil;

import android.accessibilityservice.AccessibilityService;
import android.view.accessibility.AccessibilityNodeInfo;

import com.kk.R;
import com.kk.permission.accessibilityutils.NodeUtil;
import com.kk.permission.huawei.HuaweiActionUtil;
import com.kk.permission.huawei.HuaweiTool;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HuaweiShortCutUtil {
    private final String STEP1 = "step1";
    private final String STEP2 = "step2";
    private final String STEP3 = "step3";
    private final String STEP4 = "step4";
    private final String STEP5 = "step5";
    private String mAppName = HuaweiTool.getAppName();
    public boolean result = false;
    private Map<String, String> stepMap = new HashMap();

    public boolean shortcut(AccessibilityNodeInfo accessibilityNodeInfo, AccessibilityService accessibilityService) {
        if (this.result) {
            return true;
        }
        if (NodeUtil.pageContains(accessibilityNodeInfo, HuaweiTool.getString(R.string.accessiblity_permission_huawei_shortcut_manager)) && NodeUtil.pageContains(accessibilityNodeInfo, HuaweiTool.getString(R.string.accessiblity_permission_huawei_shoutcut_permission_app))) {
            if (this.stepMap.containsKey("step4")) {
                this.stepMap.put("step5", "1");
                this.result = true;
                HuaweiTool.actionShortCutDone();
                NodeUtil.back(accessibilityService);
            } else {
                String string = HuaweiTool.getString(R.string.accessiblity_permission_huawei_shortcut_manager_title);
                List findAccessibilityNodeInfosByText = accessibilityNodeInfo.findAccessibilityNodeInfosByText(string);
                if (findAccessibilityNodeInfosByText == null || findAccessibilityNodeInfosByText.size() <= 0) {
                    if (!this.stepMap.containsKey("step1")) {
                        HuaweiActionUtil.scrollForward(accessibilityNodeInfo);
                    }
                } else if (!this.stepMap.containsKey("step1")) {
                    this.stepMap.put("step1", "1");
                    NodeUtil.clickByText(accessibilityNodeInfo, string);
                }
            }
        } else if (NodeUtil.pageContains(accessibilityNodeInfo, HuaweiTool.getString(R.string.accessiblity_permission_huawei_shortcut_manager_title)) && NodeUtil.pageContains(accessibilityNodeInfo, HuaweiTool.getString(R.string.accessiblity_permission_huawei_shoutcut_permission_cancle)) && this.stepMap.containsKey("step2") && !this.stepMap.containsKey("step3")) {
            this.stepMap.put("step3", "1");
            NodeUtil.clickByText(accessibilityNodeInfo, HuaweiTool.getString(R.string.huawei_mha_al00_confirm));
        } else if (NodeUtil.pageContains(accessibilityNodeInfo, HuaweiTool.getString(R.string.accessiblity_permission_huawei_shortcut_manager_title))) {
            if (this.stepMap.containsKey("step1") && !this.stepMap.containsKey("step2")) {
                List findAccessibilityNodeInfosByText2 = accessibilityNodeInfo.findAccessibilityNodeInfosByText(this.mAppName);
                if (findAccessibilityNodeInfosByText2 == null || findAccessibilityNodeInfosByText2.size() <= 0) {
                    HuaweiActionUtil.scrollForward(accessibilityNodeInfo);
                } else {
                    this.stepMap.put("step2", "1");
                    NodeUtil.clickByText(accessibilityNodeInfo, this.mAppName);
                }
            } else if (this.stepMap.containsKey("step3") && !this.stepMap.containsKey("step4")) {
                this.stepMap.put("step4", "1");
                NodeUtil.back(accessibilityService);
            }
        }
        return false;
    }

    public boolean shortcut2(AccessibilityNodeInfo accessibilityNodeInfo, AccessibilityService accessibilityService) {
        if (this.result) {
            return true;
        }
        if (NodeUtil.pageContains(accessibilityNodeInfo, HuaweiTool.getString(R.string.accessiblity_permission_huawei_shortcut_manager)) && NodeUtil.pageContains(accessibilityNodeInfo, HuaweiTool.getString(R.string.accessiblity_permission_huawei_shoutcut_permission_app))) {
            if (!this.stepMap.containsKey("step5") || this.stepMap.containsKey("step6")) {
                List findAccessibilityNodeInfosByText = accessibilityNodeInfo.findAccessibilityNodeInfosByText(this.mAppName);
                if (findAccessibilityNodeInfosByText == null || findAccessibilityNodeInfosByText.size() <= 0) {
                    if (!this.stepMap.containsKey("step1")) {
                        HuaweiActionUtil.scrollForward(accessibilityNodeInfo);
                    }
                } else if (!this.stepMap.containsKey("step1")) {
                    this.stepMap.put("step1", "1");
                    NodeUtil.clickByText(accessibilityNodeInfo, this.mAppName);
                }
            } else {
                this.stepMap.put("step6", "1");
                this.result = true;
                HuaweiTool.actionShortCutDone();
                NodeUtil.back(accessibilityService);
                return true;
            }
        } else if (NodeUtil.pageContains(accessibilityNodeInfo, "应用权限") && NodeUtil.pageContains(accessibilityNodeInfo, this.mAppName)) {
            if (this.stepMap.containsKey("step1") && !this.stepMap.containsKey("step2")) {
                this.stepMap.put("step2", "1");
                NodeUtil.clickByText(accessibilityNodeInfo, "设置单项权限");
            } else if (this.stepMap.containsKey("step4") && !this.stepMap.containsKey("step5")) {
                this.stepMap.put("step5", "1");
                NodeUtil.back(accessibilityService);
            }
        } else if (NodeUtil.pageContains(accessibilityNodeInfo, this.mAppName)) {
            if (this.stepMap.containsKey("step1") && this.stepMap.containsKey("step2") && !this.stepMap.containsKey("step3")) {
                String str = "创建桌面快捷方式";
                List findAccessibilityNodeInfosByText2 = accessibilityNodeInfo.findAccessibilityNodeInfosByText(str);
                if (findAccessibilityNodeInfosByText2 == null || findAccessibilityNodeInfosByText2.size() <= 0) {
                    if (!this.stepMap.containsKey("step3")) {
                        HuaweiActionUtil.scrollForward(accessibilityNodeInfo);
                    }
                } else if (!this.stepMap.containsKey("step3")) {
                    this.stepMap.put("step3", "1");
                    HuaweiActionUtil.performSwitch(accessibilityNodeInfo, str);
                }
            } else if (this.stepMap.containsKey("step1") && this.stepMap.containsKey("step2") && this.stepMap.containsKey("step3")) {
                this.stepMap.put("step4", "1");
                NodeUtil.back(accessibilityService);
            }
        }
        return false;
    }

    public boolean shortcut3(AccessibilityNodeInfo accessibilityNodeInfo, AccessibilityService accessibilityService) {
        if (this.result) {
            return true;
        }
        if (!NodeUtil.pageContains(accessibilityNodeInfo, HuaweiTool.getString(R.string.accessiblity_permission_huawei_shortcut_manager)) || !NodeUtil.pageContains(accessibilityNodeInfo, HuaweiTool.getString(R.string.accessiblity_permission_huawei_shoutcut_permission_app))) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(HuaweiTool.getAppName());
            stringBuilder.append("权限");
            if (NodeUtil.pageContains(accessibilityNodeInfo, stringBuilder.toString()) && this.stepMap.containsKey("step1")) {
                if (!this.stepMap.containsKey("step2")) {
                    String str = "创建桌面快捷方式";
                    List findAccessibilityNodeInfosByText = accessibilityNodeInfo.findAccessibilityNodeInfosByText(str);
                    if (findAccessibilityNodeInfosByText == null || findAccessibilityNodeInfosByText.size() <= 0) {
                        HuaweiActionUtil.scrollForward(accessibilityNodeInfo);
                    } else {
                        this.stepMap.put("step2", "1");
                        HuaweiActionUtil.performSwitch(accessibilityNodeInfo, str);
                    }
                } else if (!this.stepMap.containsKey("step3")) {
                    this.stepMap.put("step3", "1");
                    NodeUtil.back(accessibilityService);
                }
            }
        } else if (this.stepMap.containsKey("step3")) {
            this.stepMap.put("step4", "1");
            this.result = true;
            HuaweiTool.actionShortCutDone();
            NodeUtil.back(accessibilityService);
            return true;
        } else {
            List findAccessibilityNodeInfosByText2 = accessibilityNodeInfo.findAccessibilityNodeInfosByText(this.mAppName);
            if (findAccessibilityNodeInfosByText2 == null || findAccessibilityNodeInfosByText2.size() <= 0) {
                if (!this.stepMap.containsKey("step1")) {
                    HuaweiActionUtil.scrollForward(accessibilityNodeInfo);
                }
            } else if (!this.stepMap.containsKey("step1")) {
                this.stepMap.put("step1", "1");
                NodeUtil.clickByText(accessibilityNodeInfo, this.mAppName);
            }
        }
        return false;
    }

    public boolean shortcut4(AccessibilityNodeInfo accessibilityNodeInfo, AccessibilityService accessibilityService) {
        if (this.result) {
            return true;
        }
        if (NodeUtil.pageContains(accessibilityNodeInfo, HuaweiTool.getString(R.string.accessiblity_permission_huawei_shortcut_manager)) && NodeUtil.pageContains(accessibilityNodeInfo, HuaweiTool.getString(R.string.accessiblity_permission_huawei_shoutcut_permission_app)) && !NodeUtil.pageContains(accessibilityNodeInfo, "基础权限管理")) {
            if (this.stepMap.containsKey("step4")) {
                this.stepMap.put("step5", "1");
                this.result = true;
                HuaweiTool.actionShortCutDone();
                NodeUtil.back(accessibilityService);
                return true;
            }
            List findAccessibilityNodeInfosByText = accessibilityNodeInfo.findAccessibilityNodeInfosByText(this.mAppName);
            if (findAccessibilityNodeInfosByText == null || findAccessibilityNodeInfosByText.size() <= 0) {
                if (!this.stepMap.containsKey("step1")) {
                    HuaweiActionUtil.scrollForward(accessibilityNodeInfo);
                }
            } else if (!this.stepMap.containsKey("step1")) {
                this.stepMap.put("step1", "1");
                NodeUtil.clickByText(accessibilityNodeInfo, this.mAppName);
            }
        } else if (NodeUtil.pageContains(accessibilityNodeInfo, HuaweiTool.getAppName())) {
            if (this.stepMap.containsKey("step1")) {
                if (!this.stepMap.containsKey("step2")) {
                    String str = "创建桌面快捷方式";
                    List findAccessibilityNodeInfosByText2 = accessibilityNodeInfo.findAccessibilityNodeInfosByText(str);
                    if (findAccessibilityNodeInfosByText2 == null || findAccessibilityNodeInfosByText2.size() <= 0) {
                        HuaweiActionUtil.scrollForward(accessibilityNodeInfo);
                    } else {
                        this.stepMap.put("step2", "1");
                        HuaweiActionUtil.performSwitch(accessibilityNodeInfo, str);
                    }
                } else if (this.stepMap.containsKey("step3") && !this.stepMap.containsKey("step4")) {
                    this.stepMap.put("step4", "1");
                    NodeUtil.back(accessibilityService);
                }
            }
        } else if (NodeUtil.pageContains(accessibilityNodeInfo, "创建桌面快捷方式") && NodeUtil.pageContains(accessibilityNodeInfo, "允许") && NodeUtil.pageContains(accessibilityNodeInfo, "提示") && NodeUtil.pageContains(accessibilityNodeInfo, "禁止") && NodeUtil.pageContains(accessibilityNodeInfo, "取消") && this.stepMap.containsKey("step2") && !this.stepMap.containsKey("step3")) {
            this.stepMap.put("step3", "1");
            NodeUtil.clickByText(accessibilityNodeInfo, "允许");
        }
        return false;
    }
}
